<?php

/**
 * LayoutBehavior class
 *
 * @author Julot <andy.julot@gmail.com>
 * @since Monday, January 30, 2012. 09:21 AM
 */
class LayoutBehavior extends CBehavior {

	public function getMenu() {
		static $menu = null;

		if (!isset($menu)) {
			$user = Yii::app()->user;
			$userModule = Yii::app()->getModule('user');
			$menu = array(
				array(
					'label'=>'File',
					'url'=>array('/file/index')
				),
				array(
					'label'=>'Upload',
					'url'=>array('/file/create')
				),
				array(
					'label'=>'Login',
					'url'=>array('/site/login'),
					'visible'=>Yii::app()->user->isGuest,
				),
				array(
					'label'=>'Logout (' . Yii::app()->user->name . ')',
					'url'=>array('/site/logout'),
					'visible'=>!Yii::app()->user->isGuest,
				)
			);
		}

		return $menu;
	}

	private $_assetsUrl;

	public function getAssetsUrl() {
		if ($this->_assetsUrl === null) {
			$path = Yii::getPathOfAlias("application.assets");
			$this->_assetsUrl = Yii::app()->assetManager->publish(
				$path, false, -1, YII_DEBUG
			);
		}
		return $this->_assetsUrl;
	}

}
